import Vue from 'vue'
import Vuex from 'vuex'
Vue.use(Vuex)

const actions = {
    
}
const mutations = {
    SET_FIRST_LEVEL_LIST(state, data) {
        state.firstLevelList = data;
        sessionStorage.setItem('firstLevelList', JSON.stringify(data));
    },
    SET_LEVEL_MAP(state, data) {
        state.levelMap = data;
        sessionStorage.setItem('levelMap', JSON.stringify(data));
    },
    CLEAR_ALL_DATA(state) {
        state.firstLevelList = null;
        state.levelMap = null;
        sessionStorage.removeItem('firstLevelList');
        sessionStorage.removeItem('levelMap');
    },
    setOrder(state, data) {
        state.order = data;
        sessionStorage.setItem("order", JSON.stringify(data));
    }
}
const state = {
    firstLevelList: JSON.parse(sessionStorage.getItem('firstLevelList')) || null,
    levelMap: JSON.parse(sessionStorage.getItem('levelMap')) || null,
    order: JSON.parse(sessionStorage.getItem("order")) || null,
}
const getters = {
    firstLevelList: state => state.firstLevelList,
    levelMap: state => state.levelMap
}

export default new Vuex.Store({
    actions,
    mutations,
    state,
    getters
})
